package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;

import org.come.Frame.ZhuFrame;
import org.come.bean.ConfigureBean;
import org.come.model.Configure;
import org.come.socket.Agreement;
import org.come.socket.DownLoadTxt;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;
import org.come.until.NumberValidator;
import org.come.until.ScrollUI;
import org.come.until.SrcollPanelUI;
import org.come.until.UserData;
import org.come.until.UserMessUntil;
import org.soaring.btn.CharacterBtn;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.JpanelOnJalbelBtn;
import com.tool.btn.RoleCaoZuoBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
/**
 * 全民竞猜
 * @author Administrator
 *
 */
public class LotteryCPJpanel extends JPanel {

	private static RoleCaoZuoBtn numbtn,emptynum,refreshbtn,purchasebtn;// 号码
    private static JLabel labtext5;// 
    private JLabel labtext1, labtext2,// 
            labtext3,labtext4,labtext6,labtext7,labtext8,labtext9,labtext10;// 
//    public JLabel labtext8,labtext9;
    private static JTextField findName,findName1;
    private Set<Integer> days=new HashSet<>();
    private Set<Integer> lqs=new HashSet<>(); 
    private static String numbers = "";//所选号码
    public static String previousmsg = "";//往期中奖信息
    public static String previousmsg1 = "";//往期中奖信息
    public static String previousmsg2 = "";//往期中奖信息
    public static String[] previousmsg3 = {};//购买信息
    private Map<String, String> map = new HashMap<>();
    // 滚动条
    private JScrollPane jScrollPane;
    // 内容
    private static JList<String> listPank;
    // 选中的
    private static DefaultListModel<String> pankModel;

    public static String[] zodiac = {"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
    
    /** 刷新间隔 */
	private static long time;
	
    public LotteryCPJpanel() {
		String style = MyIsif.getStyle();
		if ("水墨UI".equals(style)) {
        this.setPreferredSize(new Dimension(605, 400));
        this.setLayout(null);
        this.setBackground(UIUtils.Color_BACK);
		// 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/background/gift-close-btn.png", 1, 1105);
        offBtn.setBounds(605-35, 20, 18, 18);
        this.add(offBtn);
		Font font;
		labtext1 = new JLabel();
		labtext1.setForeground(Color.BLACK);
		labtext1.setFont(UIUtils.TEXT_FONTZSRL);
		labtext1.setBounds(257, 5, 150, 50);
		labtext1.setText("全民竞猜");
		this.add(labtext1);
		labtext2 = new JLabel();
		labtext2.setForeground(Color.BLACK);
		labtext2.setFont(UIUtils.TEXT_FONTZS);
		labtext2.setText("往期开奖");
		labtext2.setBounds(187, 50, 150, 50);
		this.add(labtext2);
		
		
		font = new Font("宋体", Font.PLAIN, 14);
		labtext3 = new JLabel();
		labtext3.setForeground(Color.BLACK);
		labtext3.setFont(font);
		labtext3.setText("已选生肖：");
		labtext3.setBounds(35, 308, 150, 50);
		this.add(labtext3);
		
		labtext4 = new JLabel();
		labtext4.setForeground(Color.BLACK);
		labtext4.setFont(font);
		labtext4.setText("购买金额：");
		labtext4.setBounds(216, 308, 150, 50);
		this.add(labtext4);
		font = new Font("小篆", Font.BOLD, 18);
		labtext5 = new JLabel();
		labtext5.setForeground(Color.BLACK);
		labtext5.setFont(font);
		labtext5.setText("");
		labtext5.setBounds(106, 308, 150, 50);
		this.add(labtext5);
		
		findName = new JTextField();// 金额输入框
		findName.setDocument(new NumberValidator(10));
		findName.setBounds(285, 325, 128, 18);
        findName.setOpaque(false);
        findName.setBorder(BorderFactory.createEmptyBorder());
        findName.setForeground(Color.black);
        findName.setCaretColor(Color.black);
        findName.setFont(new Font("宋体",Font.PLAIN,15));
        this.add(findName);
        
        
        jScrollPane = new JScrollPane(listPank);
        jScrollPane.setVerticalScrollBarPolicy(22);
        jScrollPane.getVerticalScrollBar().setUI(new ScrollUI());
        jScrollPane.getViewport().setOpaque(false);
        jScrollPane.setOpaque(false);
        jScrollPane.setBounds(430, 57, 153, 287);
        jScrollPane.setBorder(BorderFactory.createEmptyBorder());
        jScrollPane.setHorizontalScrollBarPolicy(31);
        this.add(jScrollPane);
//        font = new Font("小篆", Font.PLAIN, 16);
//        labtext6 = new JLabel();
//        labtext6.setForeground(Color.BLACK);
//        labtext6.setFont(font);
//        labtext6.setText("规则说明：");
//        labtext6.setBounds(106, 308, 150, 50);
//		this.add(labtext6);
		
		String str="<html>玩家每次可选择3个生肖，可重复选择同一个生肖，如果猜中生肖，将获得奖励，系统每10分钟开一奖，详细中奖规则请咨询【大话精灵】！</html>";
		font = new Font("楷体", Font.PLAIN, 16);
		labtext7 = new JLabel();
		labtext7.setForeground(Color.BLACK);
        labtext7.setFont(font);
        labtext7.setText(str);
        labtext7.setBounds(40, 128, 370, 150);
		this.add(labtext7);
		
		
		
		font = new Font("楷体", Font.PLAIN, 14);
		labtext8 = new JLabel();
		labtext8.setForeground(Color.red);
		labtext8.setFont(font);
		labtext8.setText(previousmsg);
		labtext8.setBounds(40, 25, 380, 150);
		this.add(labtext8);
		labtext9 = new JLabel();
		labtext9.setForeground(Color.red);
		labtext9.setFont(font);
		labtext9.setText(previousmsg1);
		labtext9.setBounds(40, 45, 380, 150);
		this.add(labtext9);
		labtext10 = new JLabel();
		labtext10.setForeground(Color.red);
		labtext10.setFont(font);
		labtext10.setText(previousmsg2);
		labtext10.setBounds(40, 65, 380, 150);
		this.add(labtext10);
		
		
		font = new Font("小篆", Font.BOLD, 20);
        for(int i = 0;i<zodiac.length;i++) {
			//编号
        	numbtn = new RoleCaoZuoBtn("inkImg/old/background/numbtn.png", 1, UIUtils.COLOR_BTNPUTONG, font, zodiac[i]+"",1105,"");
        	numbtn.setFont(font);
        	if (i >5) {
        		numbtn.setBounds(70+(i-6)*50, 280, 35, 35);
            } else {
            	numbtn.setBounds(70+i*50, 240, 35, 35);
            }
			this.add(numbtn);
		}
        
        font = new Font("楷体", Font.BOLD, 16);
        emptynum = new RoleCaoZuoBtn("inkImg/old/background/cxbtn.png", 1, UIUtils.COLOR_BTNPUTONG, font, "重选", 1105);
        emptynum.setBounds(130,350, 70, 35);
        this.add(emptynum);
        
        font = new Font("楷体", Font.BOLD, 16);
        refreshbtn = new RoleCaoZuoBtn("inkImg/old/background/cxbtn.png", 1, UIUtils.COLOR_BTNPUTONG, font, "刷新", 1105);
        refreshbtn.setBounds(430,350, 70, 35);
        this.add(refreshbtn);

        purchasebtn = new RoleCaoZuoBtn("inkImg/old/background/cxbtn.png", 1, UIUtils.COLOR_BTNPUTONG, font, "购买", 1105);
        purchasebtn.setBounds(250,350, 70, 35);
        this.add(purchasebtn);
        
        
		Calendar now=Calendar.getInstance();
		int year = now.get(Calendar.YEAR);
		int month = now.get(Calendar.MONTH) + 1;
		} else {
			this.setPreferredSize(new Dimension(605, 400));
			this.setLayout(null);
			this.setBackground(UIUtils.Color_BACK);
			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/hongmu/s74.png", 1, 1105);
			offBtn.setBounds(605-25, 5, 18, 18);
			this.add(offBtn);
			Font font;
			labtext1 = new JLabel();
			labtext1.setForeground(Color.white);
			labtext1.setFont(UIUtils.TEXT_FONTZSRL);
			labtext1.setBounds(257, 5, 150, 50);
			labtext1.setText("");
			this.add(labtext1);
			labtext2 = new JLabel();
			labtext2.setForeground(Color.white);
			labtext2.setFont(UIUtils.TEXT_FONTZS);
			labtext2.setText("往期开奖");
			labtext2.setBounds(187, 50, 150, 50);
			this.add(labtext2);


			font = new Font("宋体", Font.PLAIN, 14);
			labtext3 = new JLabel();
			labtext3.setForeground(Color.white);
			labtext3.setFont(font);
			labtext3.setText("已选生肖：");
			labtext3.setBounds(25, 308, 150, 50);
			this.add(labtext3);

			labtext4 = new JLabel();
			labtext4.setForeground(Color.white);
			labtext4.setFont(font);
			labtext4.setText("购买金额：");
			labtext4.setBounds(211, 308, 150, 50);
			this.add(labtext4);
			font = new Font("小篆", Font.BOLD, 18);
			labtext5 = new JLabel();
			labtext5.setForeground(Color.white);
			labtext5.setFont(font);
			labtext5.setText("");
			labtext5.setBounds(101, 308, 150, 50);
			this.add(labtext5);

			findName = new JTextField();// 金额输入框
			findName.setDocument(new NumberValidator(10));
			findName.setBounds(282, 325, 128, 18);
			findName.setOpaque(false);
			findName.setBorder(BorderFactory.createEmptyBorder());
			findName.setForeground(Color.white);
			findName.setCaretColor(Color.white);
			findName.setFont(new Font("宋体",Font.PLAIN,15));
			this.add(findName);


			jScrollPane = new JScrollPane(listPank);
			jScrollPane.setVerticalScrollBarPolicy(22);
			jScrollPane.getVerticalScrollBar().setUI(new ScrollUI());
			jScrollPane.getViewport().setOpaque(false);
			jScrollPane.setOpaque(false);
			jScrollPane.setBounds(430, 57, 153, 287);
			jScrollPane.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane.setHorizontalScrollBarPolicy(31);
			this.add(jScrollPane);
//        font = new Font("小篆", Font.PLAIN, 16);
//        labtext6 = new JLabel();
//        labtext6.setForeground(Color.BLACK);
//        labtext6.setFont(font);
//        labtext6.setText("规则说明：");
//        labtext6.setBounds(106, 308, 150, 50);
//		this.add(labtext6);

			String str="<html>玩家每次可选择3个生肖，可重复选择同一个生肖，如果猜中生肖，将获得奖励，系统每10分钟开一奖，详细中奖规则请咨询【大话精灵】！</html>";
			font = new Font("楷体", Font.PLAIN, 16);
			labtext7 = new JLabel();
			labtext7.setForeground(Color.white);
			labtext7.setFont(font);
			labtext7.setText(str);
			labtext7.setBounds(40, 128, 370, 150);
			this.add(labtext7);



			font = new Font("楷体", Font.PLAIN, 14);
			labtext8 = new JLabel();
			labtext8.setForeground(Color.red);
			labtext8.setFont(font);
			labtext8.setText(previousmsg);
			labtext8.setBounds(40, 25, 380, 150);
			this.add(labtext8);
			labtext9 = new JLabel();
			labtext9.setForeground(Color.red);
			labtext9.setFont(font);
			labtext9.setText(previousmsg1);
			labtext9.setBounds(40, 45, 380, 150);
			this.add(labtext9);
			labtext10 = new JLabel();
			labtext10.setForeground(Color.red);
			labtext10.setFont(font);
			labtext10.setText(previousmsg2);
			labtext10.setBounds(40, 65, 380, 150);
			this.add(labtext10);


			font = new Font("小篆", Font.BOLD, 20);
			for(int i = 0;i<zodiac.length;i++) {
				//编号
				numbtn = new RoleCaoZuoBtn("inkImg/old/background/numbtn.png", 1, UIUtils.COLOR_BTNPUTONG, font, zodiac[i]+"",1105,"");
				numbtn.setFont(font);
				if (i >5) {
					numbtn.setBounds(70+(i-6)*50, 280, 35, 35);
				} else {
					numbtn.setBounds(70+i*50, 240, 35, 35);
				}
				this.add(numbtn);
			}

			font = new Font("楷体", Font.BOLD, 16);
			emptynum = new RoleCaoZuoBtn("inkImg/old/background/cxbtn.png", 1, UIUtils.COLOR_BTNPUTONG, font, "重选", 1105);
			emptynum.setBounds(130,350, 70, 35);
			this.add(emptynum);

			font = new Font("楷体", Font.BOLD, 16);
			refreshbtn = new RoleCaoZuoBtn("inkImg/old/background/cxbtn.png", 1, UIUtils.COLOR_BTNPUTONG, font, "刷新", 1105);
			refreshbtn.setBounds(370,350, 70, 35);
			this.add(refreshbtn);

			purchasebtn = new RoleCaoZuoBtn("inkImg/old/background/cxbtn.png", 1, UIUtils.COLOR_BTNPUTONG, font, "购买", 1105);
			purchasebtn.setBounds(250,350, 70, 35);
			this.add(purchasebtn);


			Calendar now=Calendar.getInstance();
			int year = now.get(Calendar.YEAR);
			int month = now.get(Calendar.MONTH) + 1;
		}
    }

    private ImageIcon icon = CutButtonImage.getImage("inkImg/old/background/jcdt.png", 605, 400);
	private ImageIcon icon1 = CutButtonImage.getImage("inkImg/hongmu/quanmingjingcai.png", 605, 400);

    public static int getCurrentMonthDay() {
        Calendar a = Calendar.getInstance();
        a.set(Calendar.DATE, 1);
        a.roll(Calendar.DATE, -1);
        int maxDate = a.get(Calendar.DATE);
        return maxDate;
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
		String style = MyIsif.getStyle();
		if ("水墨UI".equals(style)) {
        g.drawImage(this.icon.getImage(), 0, 0, 605, 400, this);
//        previousmsg = "第0001期，开奖号码：489，参与人数：2，中奖金额：30000000";
        labtext8.setText(previousmsg);
        labtext9.setText(previousmsg1);
        labtext10.setText(previousmsg2);
		} else {
			g.drawImage(this.icon1.getImage(), 0, 0, 605, 400, this);
//        previousmsg = "第0001期，开奖号码：489，参与人数：2，中奖金额：30000000";
			labtext8.setText(previousmsg);
			labtext9.setText(previousmsg1);
			labtext10.setText(previousmsg2);
		}
    }

    
    public static void ChoiceNumber(String num) {
    	if(numbers.length()>2) {
    		ZhuFrame.getZhuJpanel().addPrompt2("最多可以选择3个号！");
			return;
    	}
    	numbers = numbers+num;
    	labtext5.setText(numbers);
    }
    //重选
    public static void emptyNumber() {
    	numbers = "";
    	labtext5.setText(numbers);
    }
    //购买
    public static void purchaseNumber() {
    	DownLoadTxt.getDownLoadTxt().initMes("configure.txt");
    	ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
    	Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
    	Configure configure = item.get(new BigDecimal(1));
    	
    	if("关".equals(configure.getQmjckg())) {
    		ZhuFrame.getZhuJpanel().addPrompt2("购买通道暂时关闭，请等待通知！");
			return;
    	}
    	if(numbers.length()!=3) {
    		ZhuFrame.getZhuJpanel().addPrompt2("必须选择3个号码！");
    		return;
    	}
    	if(numbers.length()>0 && findName.getText().length()>0) {
    		if(Integer.parseInt(findName.getText())<200000 || Integer.parseInt(findName.getText()) % 100 != 0) {
    			ZhuFrame.getZhuJpanel().addPrompt2("最低购买20W两！并且是100的倍数！");
    			return;
    		}
//    		//system.out.println("购买号码："+numbers+"   购买金额："+findName.getText());
//    		ZhuFrame.getZhuJpanel().addPrompt2("购买号码："+numbers+"   购买金额："+findName.getText());
    		if(UserData.uptael(Long.parseLong(findName.getText()))) {
    			String msg = "QMJC="+numbers+"|"+findName.getText();
    			SendMessageUntil.toServer(Agreement.getAgreement().LotteryCPAgreement(msg));
    		}
    	}else {
    		if("".equals(numbers)) {
    			ZhuFrame.getZhuJpanel().addPrompt2("请选择号码！");
    			return;
    		}
    		if("".equals(findName.getText())) {
    			ZhuFrame.getZhuJpanel().addPrompt2("请输入金额！");
    			return;
    		}
    	}
    }
    
    
    public Set<Integer> getDays() {
        return days;
    }

    public void setDays(Set<Integer> days) {
        this.days = days;
    }

    public Set<Integer> getLqs() {
        return lqs;
    }

    public void setLqs(Set<Integer> lqs) {
        this.lqs = lqs;
    }

	public Map<String, String> getMap() {
		return map;
	}

	public void setMap(Map<String, String> map) {
		this.map = map;
	}
	
	
	
	//
    public static void getlisysta() {
    	pankModel = new DefaultListModel<String>();
    	for(int i = previousmsg3.length-1; i>=0; i--) {
    		// 申请列表
    		listPank = new JList<String>();
    		listPank.setSelectionBackground(new Color(33, 42, 52));
    		listPank.setSelectionForeground(Color.yellow);
//    		if(previousmsg3[i].split(",")[2].equals("已中奖")) {
//    			listPank.setForeground(Color.red);
//    		}else if(previousmsg3[i].split(",")[2].equals("未开奖")) {
//    			listPank.setForeground(Color.gray);
//    		}else {
//    			listPank.setForeground(Color.black);
//    		}
    		listPank.setForeground(Color.black);
    		listPank.setFont(new Font("宋体", 0, 12));
    		listPank.setBackground(new Color(0, 0, 0, 0)); // 设置列表框为透明背景
    		listPank.setFixedCellHeight(25);
    		pankModel.addElement(previousmsg3[i]);
    		listPank.setModel(pankModel);
    	}
    }

	public void getjScrollPane() {
		// 购买记录滚动条
        jScrollPane = new JScrollPane(listPank);
        jScrollPane.setVerticalScrollBarPolicy(22);
        jScrollPane.getVerticalScrollBar().setUI(new ScrollUI());
        jScrollPane.getViewport().setOpaque(false);
        jScrollPane.setOpaque(false);
        jScrollPane.setBounds(435, 57, 148, 287);
        jScrollPane.setBorder(BorderFactory.createEmptyBorder());
        jScrollPane.setHorizontalScrollBarPolicy(31);
        this.add(jScrollPane);
//		return jScrollPane;
	}

	
	public void deleteScrollPane() {
        this.remove(jScrollPane);
	}

	public void setjScrollPane(JScrollPane jScrollPane) {
		this.jScrollPane = jScrollPane;
	}
    
	public static void refresh() {
		long time2 = System.currentTimeMillis();
		if (time2 - time < 300000) {
			ZhuFrame.getZhuJpanel().addPrompt("5分钟内之能刷新一次！");
			return;
		}
		time = time2;
		SendMessageUntil.toServer(Agreement.getAgreement().LotteryCPAgreement("QPEN"));
	}
	
    
    
    
    
}
